#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2021/6/24 15:55
# @Author    :cjw
from typing import Optional
from faker import Factory


class GenerateData:
	"""数据生成"""

	def __init__(self, locale: str = 'zh_CN'):
		self.faker = Factory.create(locale)

	def name(self, num: Optional[int] = None):
		"""
		姓名
		:param num: 生成数量
		:return:
		"""
		if num:
			name = [self.faker.name() for _ in range(num)]
		else:
			name = self.faker.name()
		return name

	def phone(self, num: Optional[int] = None):
		"""
		手机号
		:param num:
		:return:
		"""
		if num:
			phone = [self.faker.phone_number() for _ in range(num)]
		else:
			phone = self.faker.phone_number()
		return phone

	def id_card(self, num: Optional[int] = None, min_age: int = 18,
	            max_age: int = 90, gender: Optional[str] = None):
		"""
		身份证：可以指定生成年龄段
		:param num: 数量
		:param min_age: 最小年龄
		:param max_age: 最大年龄
		:param gender: 性别，男性：M/m，女性：F/f, 不指定随机生成性别的身份证
		:return:
		"""
		if num:
			id_card = [self.faker.ssn(min_age, max_age, gender) for _ in range(num)]
		else:
			id_card = self.faker.ssn(min_age, max_age, gender)
		return id_card

	def email(self, num: Optional[int] = None, domain: Optional[str] = None):
		"""
		邮箱
		:param num: 生成数量
		:param domain: 邮箱域名：例如’qq.com‘
		:return:
		"""
		if num:
			email = [self.faker.email(domain) for _ in range(num)]
		else:
			email = self.faker.email(domain)
		return email

	def word(self, is_words: bool = False, nb=3, ext_word_list=None, unique=False):
		"""
		文字词组
		:param is_words: 是否生成多个
		:param nb: 生成多个词组的数量，默认是3
		:param ext_word_list: 生成额外的词组列表
		:param unique: 是否唯一
		:return:
		"""
		if is_words:
			return self.faker.words(nb, ext_word_list, unique)
		else:
			return self.faker.word(ext_word_list)


if __name__ == '__main__':
	gd = GenerateData()
	print(gd.name(10))
	print(gd.phone(10))
	print(gd.id_card())
	print(gd.email())
